#include "task_default.h"
#include "task.h"
#include "task_manager.h"
#include "log.h"

#include "mm_task.h"
#include "msg_task.h"
#include "pcap_task.h"
#include "socket_task.h"

#include "packet_free_task.h"
#include "opendpi_task.h"
#include "opendpi_db_task.h"
#include "opendpi_packets_top5.h"
#include "opendpi_bytes_top5.h"
#include "http_parse_task.h"

/* test code */
#include "test_task.h"
#include "test_dpi_task.h"
#include "test_dpi_task2.h"
#include "test_dpi_task3.h"

int default_task_init(struct task_manager *task_manager)
{
	log_info("begin default_task_init.");
	if (task_manager == NULL) {
		log_error("task_manager is NULL.");
		return -1;
	}

	/*
	 * Add default task here.
	 * Notice: the sequence of register is very important.
	 * */

	int ret = 0;
	ret = register_default_task(task_manager, "msg_task", msg_loop, msg_ops);
	if (ret != 0) {
		log_error("register_default_task failed, ret = %d", ret);
		/* go on, no return or exit */
	}

	ret = register_default_task(task_manager, "mm_task", mm_loop, mm_ops);
	if (ret != 0) {
		log_error("register_default_task failed, ret = %d", ret);
		/* go on, no return or exit */
	}

	ret = register_default_task(task_manager, "pcap_task", pcap_main, pcap_ops);
	if (ret != 0) {
		log_error("register_default_task failed, ret = %d", ret);
		/* go on, no return or exit */
	}
	ret = register_default_task(task_manager, "socket_task",socket_main,socket_ops);
	if (ret != 0) {
		log_error("register_default_task failed, ret = %d", ret);
		/*go on ,no return or exit */
	} 

	ret = register_default_task(task_manager, "packet_free_task", packet_free_loop, packet_free_ops);
	if (ret != 0) {
		log_error("register_default_task failed, ret = %d", ret);
		/* go on, no return or exit */
	}

	ret = register_plugin_task(task_manager, "opendpi_task", opendpi_loop, opendpi_ops);
	if (ret != 0) {
		log_error("register_plugin_task failed, ret = %d", ret);
		/* go on, no return or exit */
	}

	ret = register_plugin_task(task_manager, "http_parse_task", http_parse_loop, http_parse_ops);
	if (ret != 0) {
		log_error("register_plugin_task failed, ret = %d", ret);
		/* go on, no return or exit */
	}

	ret = register_plugin_task(task_manager, "opendpi_db_task", opendpi_db_loop, opendpi_db_ops);
	if (ret != 0) {
		log_error("register_plugin_task failed, ret = %d", ret);
		/* go on, no return or exit */
	}

	ret = register_plugin_task(task_manager, "opendpi_packets_top5_task", opendpi_packets_top5_loop, opendpi_packets_top5_ops);
	if (ret != 0) {
		log_error("register_plugin_task failed, ret = %d", ret);
		/* go on, no return or exit */
	}

	ret = register_plugin_task(task_manager, "opendpi_bytes_top5_task", opendpi_bytes_top5_loop, opendpi_bytes_top5_ops);
	if (ret != 0) {
		log_error("register_plugin_task failed, ret = %d", ret);
		/* go on, no return or exit */
	}

#if 0
	ret = register_plugin_task(task_manager, "test_dpi_task", test_dpi_loop, test_dpi_ops);
	if (ret != 0) {
		log_error("register_default_task failed, ret = %d", ret);
		/* go on, no return or exit */
	}

	ret = register_plugin_task(task_manager, "test_dpi_task2", test_dpi_loop2, test_dpi_ops2);
	if (ret != 0) {
		log_error("register_default_task failed, ret = %d", ret);
		/* go on, no return or exit */
	}

	ret = register_plugin_task(task_manager, "test_dpi_task3", test_dpi_loop3, test_dpi_ops3);
	if (ret != 0) {
		log_error("register_default_task failed, ret = %d", ret);
		/* go on, no return or exit */
	}

	ret = register_default_task(task_manager, "test1", test_func1, msg_ops1);
	if (ret != 0) {
		log_error("register_default_task failed, ret = %d", ret);
		/* go on, no return or exit */
	}

	ret = register_default_task(task_manager, "test2", test_func2, msg_ops2);
	if (ret != 0) {
		log_error("register_default_task failed, ret = %d", ret);
		/* go on, no return or exit */
	}

	ret = register_default_task(task_manager, "test3", test_func3, msg_ops3);
	if (ret != 0) {
		log_error("register_default_task failed, ret = %d", ret);
		/* go on, no return or exit */
	}

	ret = register_default_task(task_manager, "test4", test_func4, msg_ops4);
	if (ret != 0) {
		log_error("register_default_task failed, ret = %d", ret);
		/* go on, no return or exit */
	}

	ret = register_default_task(task_manager, "test5", test_func5, msg_ops5);
	if (ret != 0) {
		log_error("register_default_task failed, ret = %d", ret);
		/* go on, no return or exit */
	}

	ret = register_default_task(task_manager, "test6", test_func6, msg_ops6);
	if (ret != 0) {
		log_error("register_default_task failed, ret = %d", ret);
		/* go on, no return or exit */
	}

	ret = register_plugin_task(task_manager, "test7", test_func7, msg_ops7);
	if (ret != 0) {
		log_error("register_default_task failed, ret = %d", ret);
		/* go on, no return or exit */
	}

	ret = register_plugin_task(task_manager, "test8", test_func8, msg_ops8);
	if (ret != 0) {
		log_error("register_default_task failed, ret = %d", ret);
		/* go on, no return or exit */
	}

	ret = register_plugin_task(task_manager, "test9", test_func9, msg_ops9);
	if (ret != 0) {
		log_error("register_default_task failed, ret = %d", ret);
		/* go on, no return or exit */
	}
#endif
	return 0;
}
